#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
int main()
{
#ifdef LOCAL
    freopen("ALGO-79.in", "r", stdin);
#endif
    int n, t; cin >> n;
    while(n--)
    {
        cin >> t;
        if(t != 0) ans.push_back(t);
    }
    cout << ans.size() << endl;
    bool first = true;
    for(int i = 0; i < ans.size(); ++i)
    {
        cout << (first ? "" : " ") << ans[i], first = false;
    }
    return 0;
}